<!DOCTYPE html>
<html>
<head>
    <title>新增用户</title>
    {% include 'admin/common/header.html' %}
</head>
<body>
<form class="layui-form" action="">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">
                 <div class="layui-form-item layui-hide">
                    <label class="layui-form-label">编号</label>
                    <div class="layui-input-block">
                        <input type="text"  value="{{ member.id }}" name="memberId" lay-verify="title"
                               autocomplete="off" placeholder="请输入角色组名称" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item" id="openTypeItem">
                    <label class="layui-form-label">角色组</label>
                    <div class="layui-input-block">
                        <select name="memberroleid" id="openType">
                            <option value=""></option>
                            <option value="_iframe">框架</option>
                            <option value="_blank">签页</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">用户名</label>
                    <div class="layui-input-block">
                        <input type="text" name="username" value="{{ member.username }}" lay-verify="title" autocomplete="off" placeholder="请输入用户名"
                               class="layui-input">
                    </div>
                </div>
{#                <div class="layui-form-item">#}
{#                    <label class="layui-form-label">密码</label>#}
{#                    <div class="layui-input-block">#}
{#                        <input type="password" name="password" lay-verify="title" autocomplete="off" placeholder="请输入密码"#}
{#                               class="layui-input">#}
{#                    </div>#}
{#                </div>#}
                <div class="layui-form-item">
                    <label class="layui-form-label">邮箱</label>
                    <div class="layui-input-block">
                        <input type="text" name="mailbox"  value="{{ member.mailbox }}" lay-verify="title" autocomplete="off" placeholder="请输入邮箱"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">在职状态</label>
                    <div class="layui-input-block">
                        <input type="radio" name="enable" {% if member.enable == 1 %}checked {% endif %} value="1" title="在职" checked>
                        <input type="radio" name="enable" {% if member.enable == 0 %}checked {% endif %} value="0" title="离职" >
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">排序</label>
                    <div class="layui-input-block">
                        <input type="text" name="sort" value="{{ member.sort }}" lay-verify="title" autocomplete="off" placeholder="请输入标题"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">描述</label>
                    <div class="layui-input-block">
                        <textarea placeholder="请输入描述"  name="remark" class="layui-textarea">{{ member.remark }}</textarea>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit="" lay-filter="dept-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
{% include 'admin/common/footer.html' %}
        <div class="layui-form-item layui-hide">
                    <label class="layui-form-label">编号</label>
                    <div class="layui-input-block">
                        <input type="text"  id ="memberid" value="{{ member.memberrole_id }}" lay-verify="title"
                               autocomplete="off" placeholder="请输入角色组名称" class="layui-input">
                    </div>
        </div>
<script>
  layui.use(['form', 'jquery', 'dtree'], function () {
    let form = layui.form
    let $ = layui.jquery
    let id = $("#memberid").val()
    {#let dtree = layui.dtree#}
     //下拉框加载
    $.ajax({
        url: '/admin/memberrole/selectuser',
        dataType: 'json',
        type: 'get',
        success: function (data) {
            let str="<option value=''>全部</option>";
            for(let i of data.data){
                 if(i.parentId == id ){
                 str+=`<option selected value='${i.parentId}'>${i.rolename}</option>`;
                }else{
                 str+=`<option value='${i.parentId}'>${i.rolename}</option>`;
                }

            }
            $("#openType").html(str);
            form.render();
            //重新渲染 固定写法
        }
    });

    form.on('submit(dept-save)', function (data) {
        console.log(data,"fffff")
      $.ajax({
        url: '/admin/member/update',
        data: JSON.stringify(data.field),
        dataType: 'json',
        contentType: 'application/json',
        type: 'post',
        success: function (result) {
          if (result.success) {
            layer.msg(result.msg, { icon: 1, time: 1000 }, function () {
              parent.layer.close(parent.layer.getFrameIndex(window.name))
                parent.layui.table.reload('user-table')
              parent.render()
            })
          } else {
            layer.msg(result.msg, { icon: 2, time: 1000 })
          }
        }
      })
      return false
    })
  })
</script>
<script>
</script>
</body>
</html>